package concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *  测试睡眠是否会让线程返回线程池
 */
public class TestExecutorSleep {
    private static final int THREAD_POOL_SIZE = 4;
    private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(THREAD_POOL_SIZE);

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            int finalI = i + 1;
            EXECUTOR.submit(new Runnable() {
                @Override
                public void run() {
                    while (true){
                        System.out.println("第"+ finalI + "个线程执行中");
                        try {
                            Thread.sleep(5000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            });
        }
    }
}
